package com.loveprogrammer.eternity.skill.support.skills;

import com.loveprogrammer.eternity.model.Character;
import com.loveprogrammer.eternity.common.Tuple;
import com.loveprogrammer.eternity.skill.support.states.BurnState;

import java.util.ArrayList;
import java.util.List;

/**
 * @version 1.0.0
 * @description: 熔岩爆裂
 * @author: eric
 * @date: 2022-08-16 16:53
 **/
public class SkillLavaBurst extends AbstractSkill {

    public SkillLavaBurst(int id, int baseInterval, int level, int order, int maxLevel, String name, String desc) {
        super(id, baseInterval, level, order, maxLevel, name, desc);
    }

    @Override
    protected Tuple<String, List<Character>> skillLaunch(Character character,
                                                         List<? extends Character> attack,
                                                         List<? extends Character> defences) {
        Tuple<String, List<Character>> result = new Tuple<>();

        List<Character> characters = new ArrayList<>();
        // 创建一个灼烧，给所有人
        StringBuilder builder = new StringBuilder();
        builder.append(character.getName()).append("(").append(character.getCurrentHp()).append("/")
                .append(character.getHpMax()).append(")").append(" 使用技能[")
                .append(getName()).append(" ").append(getLevel()).append("级】攻击了 ").append("所有敌方目标\n");

        int power = getHarm(character);
        for (Character defence : defences) {
            // 每秒掉落生命，持续5秒
            BurnState burnState = new BurnState(defence, defences,power);
            boolean state = defence.acquireState(burnState, 5);
            // 施展成功 启动一个定时器，5秒钟
            if (state) {
                setTimeTask(burnState, 5);
                characters.add(defence);
                builder.append(defence.getName()).append("进入灼烧状态;\n");
            } else {
                builder.append(defence.getName()).append("灼烧无效;\n");
            }
        }


        result.setValue(characters);
        result.setKey(builder.toString());
        return result;
    }

    @Override
    protected int computeHarm(Character character) {
        return (int) ((getBaseHarm() + character.getMagic() * 0.4 + character.getTechnique() * 0.7) * ((100 + getLevel() * 5) / 100));
    }

    @Override
    protected int computeSecondHarm(Character character) {
        return 0;
    }

    @Override
    public boolean check(Character character) {
        if (restInterval() <= 0) {
            return true;
        }
        return false;
    }

    @Override
    public int opportunityPassive() {
        return 0;
    }

    @Override
    public boolean checkLevelUp(int characterLevel) {
        // 每3级升一级
        if (characterLevel % 3 == 0) {
            return true;
        }
        return false;
    }

    @Override
    public int defaultHarm() {
        return 30;
    }
}
